/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ClasesWeb;

import ClasesTablas.Libro;
import ClasesTablas.Revista;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author CHENTEHC
 */
@ManagedBean(name="agregar")
@SessionScoped
public class Agregar {
    
    public void AgregarLibro(Libro libro){
         Session session = null;
             Configuration configuration=new Configuration();
             SessionFactory sessionFactory=configuration.configure().buildSessionFactory();
             session=sessionFactory.openSession();
             Transaction transaction=session.beginTransaction();
             try{
                 session.beginTransaction();
                 session.save(libro);
                 session.getTransaction().commit();
             }
             catch(HibernateException e){
                
                 System.out.println(e);
                 session.getTransaction().rollback();
                 System.out.println("No se guardo );");
             
             }
    }
    public void AgregarRevista(Revista revista){
         Session session = null;
             Configuration configuration=new Configuration();
             SessionFactory sessionFactory=configuration.configure().buildSessionFactory();
             session=sessionFactory.openSession();
             Transaction transaction=session.beginTransaction();
             try{
                 session.beginTransaction();
                 session.save(revista);
                 session.getTransaction().commit();
             }
             catch(HibernateException e){
                
                 System.out.println(e);
                 session.getTransaction().rollback();
                 System.out.println("No se guardo );");
             
             }
    }
    
    
    
}
